<template>
  <el-card>
    <el-tabs>
      <el-tab-pane label="登录账户设置">
        <el-form :model="formData" label-width="120px" style="margin: 30px 0 0 120px">
          <el-form-item label="用户名">
            <el-input v-model="formData.username" style="width:300px" />
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="formData.pwd" type="password" style="width:300px" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="saveUserDetailById">更新</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="个人详情">
        <el-row type="flex" justify="end">
          <el-tooltip content="打印个人基本信息">
            <router-link :to="`/employees/print/${this.$route.params.id}?type=personal`">
              <i class="el-icon-printer" />
            </router-link>
          </el-tooltip>
        </el-row>
        <component :is="UserInfo0" />
      </el-tab-pane>
      <el-tab-pane label="岗位信息">
        <el-row type="flex" justify="end">
          <el-tooltip content="打印岗位信息">
            <router-link :to="`/employees/print/${this.$route.params.id}?type=job`">
              <i class="el-icon-printer" />
            </router-link>
          </el-tooltip>
        </el-row>
        <JobInfo />
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import { getUserDetail } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
import UserInfo from './components/user-info.vue'
import JobInfo from './components/job-info.vue'
export default {
  components: {
    UserInfo,
    JobInfo
  },
  data() {
    return {
      UserInfo0: 'user-info',
      formData: {
        username: '',
        pwd: ''
      }
    }
  },
  created() {
    this.getUserDetailById()
  },
  methods: {
    async getUserDetailById() {
    //   console.log(this.$route.params.id)
      this.formData = await getUserDetail(this.$route.params.id)
    //   console.log(res)
    },
    async saveUserDetailById(data) {
      this.formData.password = this.formData.pwd
      await saveUserDetailById(this.formData)
      this.$message.success('edit suc')
    }
  }
}
</script>

<style>

</style>
